﻿//
//  Monkey Manager
//  Copyright (C) 2012 Victor Tereschenko
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//     
// ========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ManagerDB;
using Sibvic.Command;

namespace MonkeyManager.Command
{
    class AutotagItemCompletedEventArgs : EventArgs
    {
        public AutotagItemCompletedEventArgs(StoredFile file)
        {
            FileName = file;
        }

        public StoredFile FileName
        {
            get;
            private set;
        }
    }

    class AutotagFinishEventsArgs : EventArgs
    {
    }

    class AutotagStartEventsArgs : EventArgs
    {
        public AutotagStartEventsArgs(StoredFile[] files)
        {
            Files = files;
        }

        public StoredFile[] Files
        {
            get;
            private set;
        }
    }

    class AutotagCommand : ICommand
    {
        public AutotagCommand(StoredFile[] files, IDatabase database)
        {
            mFiles = files;
            mDatabase = database;
        }

        StoredFile[] mFiles;
        IDatabase mDatabase;

        public void Execute()
        {
            Start(this, new AutotagStartEventsArgs(mFiles));
            foreach (StoredFile file in mFiles)
            {
                StoredFileController.Autotag(file);
                mDatabase.Update(file);
                AutotagCompleted(this, new AutotagItemCompletedEventArgs(file));
            }
            Finish(this, new AutotagFinishEventsArgs());
        }

        public event EventHandler<AutotagItemCompletedEventArgs> AutotagCompleted;
        public event EventHandler<AutotagFinishEventsArgs> Finish;
        public event EventHandler<AutotagStartEventsArgs> Start;
    }
}
